import {
  AbilityType,
  APIType,
  APIVersion,
  LanguageType,
  ModuleTemplateType,
  RuntimeOSType, CURRENT_HMOS_API
} from '../../../../../models/constants';
import { ModuleTemplateOption, ModuleTemplateOptionBuilder } from '../../../../../models/model-options';
import { ModuleConfigInitFun } from '../../../../../models/module-models';
import { copyTmp, DirTemplateCreator, dirTmp, renderTmp } from '../../../../../models/template-models';
import { entryBuilder, moduleBuilder } from '../../../../../module-builder';

/**
 * Entry
 *
 * @type {ModuleTemplateOption}
 */
const emptyAbilityEntryOption: ModuleTemplateOption = ModuleTemplateOptionBuilder.builder()
  .abilityType(AbilityType.Application)
  .apiType(APIType.STAGE)
  .apiVersion(CURRENT_HMOS_API)
  .language(LanguageType.ArkTs)
  .moduleTemplateType(ModuleTemplateType.EmptyAbility)
  .runtimeOS(RuntimeOSType.HarmonyOS)
  .build();


const emptyAbilityEntryTemplate: DirTemplateCreator = (dirName) => dirTmp(dirName)
  .add(dirTmp('.test')
    .add(dirTmp('testability')
      .add(copyTmp('/common/localUnitTest/.test/testability/TestAbility.ets'))
      .add(dirTmp('pages')
        .add(copyTmp('/common/localUnitTest/.test/testability/pages/Index.ets'))
      )
    )
  )
  .add(dirTmp('src')
    .add(dirTmp('main')
      .add(dirTmp('ets')
        .add(copyTmp('/entry/stage/app/emptyAbility/api18/src/main/ets/entryability'))
        .add(copyTmp('/entry/stage/app/emptyAbility/api18/src/main/ets/pages'))
      )
      .add(dirTmp('resources')
        .add(dirTmp('base')
          .add(dirTmp('element')
            .add(copyTmp('/entry/stage/app/emptyAbility/api18/src/main/resources/base/element/color.json'))
            .add(copyTmp('/entry/stage/app/emptyAbility/api18/src/main/resources/base/element/string.json'))
          )
          .add(copyTmp('/entry/stage/app/emptyAbility/api18/src/main/resources/base/media'))
          .add(copyTmp('/entry/stage/app/emptyAbility/api18/src/main/resources/base/profile'))
        )
        .add(copyTmp('/entry/stage/app/emptyAbility/api18/src/main/resources/en_US'))
        .add(dirTmp('rawfile'))
        .add(copyTmp('/entry/stage/app/emptyAbility/api18/src/main/resources/zh_CN'))
      )
      .add(renderTmp('/entry/stage/app/emptyAbility/api18/src/main/module.json5'))
    )
    .add(dirTmp('ohosTest')
      .add(copyTmp('/entry/stage/app/emptyAbility/api18/src/ohosTest/ets'))
      .add(copyTmp('/entry/stage/app/emptyAbility/api18/src/ohosTest/resources'))
      .add(renderTmp('/entry/stage/app/emptyAbility/api18/src/ohosTest/module.json5'))
    )
    .add(copyTmp('/entry/stage/app/emptyAbility/api18/src/test'))
  )
  .add(renderTmp('/entry/stage/app/emptyAbility/api18/build-profile.json5'))
  .add(copyTmp('/module/stage/app/common/hvigorfile-hap.ts', 'hvigorfile.ts'))
  .add(copyTmp('/module/stage/app/common/obfuscation-rules.txt'))
  .add(renderTmp('/module/stage/app/common/oh-package.json5'));

const initFun: ModuleConfigInitFun = async (name, option, template) => {
  template.node('src').node('main').node('module.json5').data = { moduleName: name };
  if (template.node('src').node('ohosTest')) {
    template.node('src').node('ohosTest').node('module.json5').data = { moduleName: name };
  }
  template.node('build-profile.json5').data = { apiType: option.apiType, runtimeOS: option.runtimeOS };
  template.node('oh-package.json5').data = { moduleName: name, main: 'Index.ets' };
};

entryBuilder.add(emptyAbilityEntryOption, emptyAbilityEntryTemplate, initFun);


const emptyAbilityOption: ModuleTemplateOption = ModuleTemplateOptionBuilder.builder()
  .abilityType(AbilityType.Application)
  .apiType(APIType.STAGE)
  .apiVersion(CURRENT_HMOS_API)
  .language(LanguageType.ArkTs)
  .moduleTemplateType(ModuleTemplateType.EmptyAbility)
  .runtimeOS(RuntimeOSType.HarmonyOS)
  .build();


const emptyAbilityTemplate: DirTemplateCreator = (dirName) => dirTmp(dirName)
  .add(dirTmp('src')
    .add(dirTmp('main')
      .add(dirTmp('ets')
        .add(copyTmp('/module/stage/app/application/api18/src/main/ets/entryability'))
        .add(copyTmp('/module/stage/app/application/api18/src/main/ets/pages'))
      )
      .add(dirTmp('resources')
        .add(dirTmp('base')
          .add(dirTmp('element')
            .add(copyTmp('/module/stage/app/application/api18/src/main/resources/base/element/color.json'))
            .add(copyTmp('/module/stage/app/application/api18/src/main/resources/base/element/string.json'))
          )
          .add(copyTmp('/module/stage/app/application/api18/src/main/resources/base/media'))
          .add(copyTmp('/module/stage/app/application/api18/src/main/resources/base/profile'))
        )
        .add(copyTmp('/module/stage/app/application/api18/src/main/resources/en_US'))
        .add(dirTmp('rawfile'))
        .add(copyTmp('/module/stage/app/application/api18/src/main/resources/zh_CN'))
      )
      .add(renderTmp('/module/stage/app/application/api18/src/main/module.json5'))
    )
    .add(dirTmp('ohosTest')
      .add(copyTmp('/module/stage/app/application/api18/src/ohosTest/ets'))
      .add(copyTmp('/module/stage/app/application/api18/src/ohosTest/resources'))
      .add(renderTmp('/module/stage/app/application/api18/src/ohosTest/module.json5'))
    )
    .add(copyTmp('/module/stage/app/application/api18/src/test'))
  )
  .add(renderTmp('/module/stage/app/application/api18/build-profile.json5'))
  .add(copyTmp('/module/stage/app/common/hvigorfile-hap.ts', 'hvigorfile.ts'))
  .add(copyTmp('/module/stage/app/common/obfuscation-rules.txt'))
  .add(renderTmp('/module/stage/app/common/oh-package.json5'));

moduleBuilder.add(emptyAbilityOption, emptyAbilityTemplate, initFun);

const listAbilityOption: ModuleTemplateOption = ModuleTemplateOptionBuilder.builder()
  .abilityType(AbilityType.Application)
  .apiType(APIType.STAGE)
  .apiVersion(CURRENT_HMOS_API)
  .language(LanguageType.ArkTs)
  .moduleTemplateType(ModuleTemplateType.ListAbility)
  .runtimeOS(RuntimeOSType.HarmonyOS)
  .build();


const listAbilityTemplate: DirTemplateCreator = (dirName) => dirTmp(dirName)
  .add(dirTmp('src')
    .add(dirTmp('main')
      .add(dirTmp('ets')
        .add(copyTmp('/module/stage/app/listApplication/api18/src/main/ets/applicationability'))
        .add(copyTmp('/module/stage/app/listApplication/api18/src/main/ets/common'))
        .add(copyTmp('/module/stage/app/listApplication/api18/src/main/ets/pages'))
        .add(copyTmp('/module/stage/app/listApplication/api18/src/main/ets/view'))
        .add(copyTmp('/module/stage/app/listApplication/api18/src/main/ets/viewmodel'))
      )
      .add(dirTmp('resources')
        .add(dirTmp('base')
          .add(dirTmp('element')
            .add(copyTmp('/module/stage/app/listApplication/api18/src/main/resources/base/element/color.json'))
            .add(copyTmp('/module/stage/app/listApplication/api18/src/main/resources/base/element/float.json'))
            .add(copyTmp('/module/stage/app/listApplication/api18/src/main/resources/base/element/string.json'))
          )
          .add(copyTmp('/module/stage/app/listApplication/api18/src/main/resources/base/media'))
          .add(copyTmp('/module/stage/app/listApplication/api18/src/main/resources/base/profile'))
        )
        .add(copyTmp('/module/stage/app/listApplication/api18/src/main/resources/en_US'))
        .add(dirTmp('rawfile'))
        .add(copyTmp('/module/stage/app/listApplication/api18/src/main/resources/zh_CN'))
      )
      .add(renderTmp('/module/stage/app/listApplication/api18/src/main/module.json5'))
    )
    .add(dirTmp('ohosTest')
      .add(copyTmp('/module/stage/app/listApplication/api18/src/ohosTest/ets'))
      .add(copyTmp('/module/stage/app/listApplication/api18/src/ohosTest/resources'))
      .add(renderTmp('/module/stage/app/listApplication/api18/src/ohosTest/module.json5'))
    )
    .add(copyTmp('/module/stage/app/listApplication/api18/src/test'))
  )
  .add(renderTmp('/module/stage/app/listApplication/api18/build-profile.json5'))
  .add(copyTmp('/module/stage/app/common/hvigorfile-hap.ts', 'hvigorfile.ts'))
  .add(copyTmp('/module/stage/app/common/obfuscation-rules.txt'))
  .add(renderTmp('/module/stage/app/common/oh-package.json5'));

moduleBuilder.add(listAbilityOption, listAbilityTemplate, initFun);

const listAbilityEntryTemplate: DirTemplateCreator = (dirName) => dirTmp(dirName)
  .add(dirTmp('src')
    .add(dirTmp('main')
      .add(dirTmp('ets')
        .add(copyTmp('/entry/stage/app/listApplication/api18/src/main/ets/constants'))
        .add(copyTmp('/entry/stage/app/listApplication/api18/src/main/ets/entryability'))
        .add(copyTmp('/entry/stage/app/listApplication/api18/src/main/ets/pages'))
        .add(copyTmp('/entry/stage/app/listApplication/api18/src/main/ets/view'))
        .add(copyTmp('/entry/stage/app/listApplication/api18/src/main/ets/viewmodel'))
      )
      .add(dirTmp('resources')
        .add(dirTmp('base')
          .add(dirTmp('element')
            .add(copyTmp('/entry/stage/app/listApplication/api18/src/main/resources/base/element/color.json'))
            .add(copyTmp('/entry/stage/app/listApplication/api18/src/main/resources/base/element/float.json'))
            .add(copyTmp('/entry/stage/app/listApplication/api18/src/main/resources/base/element/string.json'))
          )
          .add(copyTmp('/entry/stage/app/listApplication/api18/src/main/resources/base/media'))
          .add(copyTmp('/entry/stage/app/listApplication/api18/src/main/resources/base/profile'))
        )
        .add(copyTmp('/entry/stage/app/listApplication/api18/src/main/resources/en_US'))
        .add(dirTmp('rawfile'))
        .add(copyTmp('/entry/stage/app/listApplication/api18/src/main/resources/zh_CN'))
      )
      .add(renderTmp('/entry/stage/app/listApplication/api18/src/main/module.json5'))
    )
    .add(dirTmp('ohosTest')
      .add(copyTmp('/entry/stage/app/listApplication/api18/src/ohosTest/ets'))
      .add(copyTmp('/entry/stage/app/listApplication/api18/src/ohosTest/resources'))
      .add(renderTmp('/entry/stage/app/listApplication/api18/src/ohosTest/module.json5'))
    )
    .add(copyTmp('/entry/stage/app/listApplication/api18/src/test'))
  )
  .add(renderTmp('/entry/stage/app/listApplication/api18/build-profile.json5'))
  .add(copyTmp('/module/stage/app/common/hvigorfile-hap.ts', 'hvigorfile.ts'))
  .add(copyTmp('/module/stage/app/common/obfuscation-rules.txt'))
  .add(renderTmp('/module/stage/app/common/oh-package.json5'));

entryBuilder.add(listAbilityOption, listAbilityEntryTemplate, initFun);

const nativeAbilityOption: ModuleTemplateOption = ModuleTemplateOptionBuilder.builder()
  .abilityType(AbilityType.Application)
  .apiType(APIType.STAGE)
  .apiVersion(CURRENT_HMOS_API)
  .language(LanguageType.ArkTs)
  .moduleTemplateType(ModuleTemplateType.NativeC)
  .runtimeOS(RuntimeOSType.HarmonyOS)
  .build();

const nativeAbilityTemplate: DirTemplateCreator = (dirName) => dirTmp(dirName)
  .add(dirTmp('src')
    .add(dirTmp('main')
      .add(dirTmp('cpp')
        .add(dirTmp('types'))
        .add(dirTmp('libentry'))
        .add(copyTmp('/module/stage/app/nativeApplication/api18/src/main/cpp/types/libentry/index.d.ts'))
        .add(renderTmp('/module/stage/app/nativeApplication/api18/src/main/cpp/types/libentry/oh-package.json5'))
        .add(copyTmp('/module/stage/app/nativeApplication/api18/src/main/cpp/CMakeLists.txt'))
        .add(renderTmp('/module/stage/app/nativeApplication/api18/src/main/cpp/hello.cpp'))
      )
      .add(dirTmp('ets')
        .add(copyTmp('/module/stage/app/nativeApplication/api18/src/main/ets/entryability'))
        .add(copyTmp('/module/stage/app/nativeApplication/api18/src/main/ets/pages'))
      )
      .add(dirTmp('resources')
        .add(dirTmp('base')
          .add(dirTmp('element')
            .add(copyTmp('/module/stage/app/nativeApplication/api18/src/main/resources/base/element/color.json'))
            .add(copyTmp('/module/stage/app/nativeApplication/api18/src/main/resources/base/element/string.json'))
          )
          .add(copyTmp('/module/stage/app/nativeApplication/api18/src/main/resources/base/media'))
          .add(copyTmp('/module/stage/app/nativeApplication/api18/src/main/resources/base/profile'))
        )
        .add(copyTmp('/module/stage/app/nativeApplication/api18/src/main/resources/en_US'))
        .add(dirTmp('rawfile'))
        .add(copyTmp('/module/stage/app/nativeApplication/api18/src/main/resources/zh_CN'))
      )
      .add(renderTmp('/module/stage/app/nativeApplication/api18/src/main/module.json5'))
    )
    .add(dirTmp('ohosTest')
      .add(copyTmp('/module/stage/app/nativeApplication/api18/src/ohosTest/ets'))
      .add(copyTmp('/module/stage/app/nativeApplication/api18/src/ohosTest/resources'))
      .add(renderTmp('/module/stage/app/nativeApplication/api18/src/ohosTest/module.json5'))
    )
    .add(copyTmp('/module/stage/app/nativeApplication/api18/src/test'))
  )
  .add(renderTmp('/module/stage/app/nativeApplication/api18/build-profile.json5'))
  .add(copyTmp('/module/stage/app/common/hvigorfile-hap.ts', 'hvigorfile.ts'))
  .add(copyTmp('/module/stage/app/common/obfuscation-rules.txt'))
  .add(renderTmp('/module/stage/app/common/oh-package.json5'));

const nativeInitFun: ModuleConfigInitFun = async (name, option, template) => {
  // eslint-disable-next-line max-len
  template.node('src').node('main').node('cpp').node('types').node('libapplication').node('oh-package.json5').data = { moduleName: name };
  template.node('src').node('main').node('cpp').node('CMakeLists.txt').data = { moduleName: name };
  template.node('src').node('main').node('module.json5').data = { moduleName: name };
  template.node('src').node('ohosTest').node('module.json5').data = { moduleName: name };
  template.node('build-profile.json5').data = { apiType: option.apiType, runtimeOS: option.runtimeOS };
  template.node('oh-package.json5').data = { moduleName: name };
};

moduleBuilder.add(nativeAbilityOption, nativeAbilityTemplate, nativeInitFun);
const nativeAbilityEntryTemplate: DirTemplateCreator = (dirName) => dirTmp(dirName)
  .add(dirTmp('src')
    .add(dirTmp('main')
      .add(dirTmp('cpp')
        .add(dirTmp('types'))
        .add(dirTmp('libentry'))
        .add(copyTmp('/entry/stage/app/nativeApplication/api18/src/main/cpp/types/libentry/index.d.ts'))
        .add(renderTmp('/entry/stage/app/nativeApplication/api18/src/main/cpp/types/libentry/oh-package.json5'))
        .add(copyTmp('/entry/stage/app/nativeApplication/api18/src/main/cpp/CMakeLists.txt'))
        .add(renderTmp('/entry/stage/app/nativeApplication/api18/src/main/cpp/hello.cpp'))
      )
      .add(dirTmp('ets')
        .add(copyTmp('/entry/stage/app/nativeApplication/api18/src/main/ets/entryability'))
        .add(copyTmp('/entry/stage/app/nativeApplication/api18/src/main/ets/pages'))
      )
      .add(dirTmp('resources')
        .add(dirTmp('base')
          .add(dirTmp('element')
            .add(copyTmp('/entry/stage/app/nativeApplication/api18/src/main/resources/base/element/color.json'))
            .add(copyTmp('/entry/stage/app/nativeApplication/api18/src/main/resources/base/element/string.json'))
          )
          .add(copyTmp('/entry/stage/app/nativeApplication/api18/src/main/resources/base/media'))
          .add(copyTmp('/entry/stage/app/nativeApplication/api18/src/main/resources/base/profile'))
        )
        .add(copyTmp('/entry/stage/app/nativeApplication/api18/src/main/resources/en_US'))
        .add(dirTmp('rawfile'))
        .add(copyTmp('/entry/stage/app/nativeApplication/api18/src/main/resources/zh_CN'))
      )
      .add(renderTmp('/entry/stage/app/nativeApplication/api18/src/main/module.json5'))
    )
    .add(dirTmp('ohosTest')
      .add(copyTmp('/entry/stage/app/nativeApplication/api18/src/ohosTest/ets'))
      .add(copyTmp('/entry/stage/app/nativeApplication/api18/src/ohosTest/resources'))
      .add(renderTmp('/entry/stage/app/nativeApplication/api18/src/ohosTest/module.json5'))
    )
    .add(copyTmp('/entry/stage/app/nativeApplication/api18/src/test'))
  )
  .add(renderTmp('/entry/stage/app/nativeApplication/api18/build-profile.json5'))
  .add(copyTmp('/module/stage/app/common/hvigorfile-hap.ts', 'hvigorfile.ts'))
  .add(copyTmp('/module/stage/app/common/obfuscation-rules.txt'))
  .add(renderTmp('/module/stage/app/common/oh-package.json5'));

entryBuilder.add(nativeAbilityOption, nativeAbilityEntryTemplate, nativeInitFun);

const shareLibraryOption: ModuleTemplateOption = ModuleTemplateOptionBuilder.builder()
  .abilityType(AbilityType.Application)
  .apiType(APIType.STAGE)
  .apiVersion(CURRENT_HMOS_API)
  .language(LanguageType.ArkTs)
  .moduleTemplateType(ModuleTemplateType.SharedLibrary)
  .runtimeOS(RuntimeOSType.HarmonyOS)
  .build();

const shareLibraryTemplate: DirTemplateCreator = (dirName) => dirTmp(dirName)
  .add(dirTmp('src')
    .add(dirTmp('main')
      .add(dirTmp('ets')
        .add(copyTmp('/module/stage/app/shareLibrary/api18/src/main/ets/pages'))
        .add(copyTmp('/module/stage/app/shareLibrary/api18/src/main/ets/utils'))
      )
      .add(dirTmp('resources')
        .add(dirTmp('base')
          .add(dirTmp('element')
            .add(copyTmp('/module/stage/app/shareLibrary/api18/src/main/resources/base/element/color.json'))
            .add(copyTmp('/module/stage/app/shareLibrary/api18/src/main/resources/base/element/string.json'))
          )
          .add(copyTmp('/module/stage/app/shareLibrary/api18/src/main/resources/base/media'))
          .add(copyTmp('/module/stage/app/shareLibrary/api18/src/main/resources/base/profile'))
        )
        .add(dirTmp('rawfile'))
      )
      .add(renderTmp('/module/stage/app/shareLibrary/api18/src/main/module.json5'))
    )
    .add(copyTmp('/module/stage/app/shareLibrary/api18/src/test'))
  )
  .add(renderTmp('/module/stage/app/shareLibrary/api18/build-profile.json5'))
  .add(copyTmp('/module/stage/app/shareLibrary/api18/Index.ets'))
  .add(copyTmp('/module/stage/app/common/hvigorfile-hsp.ts', 'hvigorfile.ts'))
  .add(copyTmp('/module/stage/app/common/obfuscation-rules.txt'))
  .add(renderTmp('/module/stage/app/shareLibrary/oh-package.json5'));

const shareLibraryinitFun: ModuleConfigInitFun = async (name, option, template) => {
  template.node('src').node('main').node('module.json5').data = { moduleName: name };
  if (template.node('src').node('ohosTest')) {
    template.node('src').node('ohosTest').node('module.json5').data = { moduleName: name };
  }
  template.node('build-profile.json5').data = { apiType: option.apiType, runtimeOS: option.runtimeOS };
  template.node('oh-package.json5').data = { moduleName: name, main: 'Index.ets' };
};

moduleBuilder.add(shareLibraryOption, shareLibraryTemplate, shareLibraryinitFun);

const staticLibraryOption: ModuleTemplateOption = ModuleTemplateOptionBuilder.builder()
  .abilityType(AbilityType.Application)
  .apiType(APIType.STAGE)
  .apiVersion(CURRENT_HMOS_API)
  .language(LanguageType.ArkTs)
  .moduleTemplateType(ModuleTemplateType.StaticLibrary)
  .runtimeOS(RuntimeOSType.HarmonyOS)
  .build();

const staticLibraryTemplate: DirTemplateCreator = (dirName) => dirTmp(dirName)
  .add(dirTmp('src')
    .add(dirTmp('main')
      .add(dirTmp('ets')
        .add(copyTmp('/module/stage/app/staticLibrary/api18/src/main/ets/components'))
      )
      .add(dirTmp('resources')
        .add(dirTmp('base')
          .add(dirTmp('element')
            .add(copyTmp('/module/stage/app/staticLibrary/api18/src/main/resources/base/element/string.json'))
          )
        )
        .add(copyTmp('/module/stage/app/staticLibrary/api18/src/main/resources/en_US'))
        .add(copyTmp('/module/stage/app/staticLibrary/api18/src/main/resources/zh_CN'))
      )
      .add(renderTmp('/module/stage/app/staticLibrary/api18/src/main/module.json5'))
    )
    .add(copyTmp('/module/stage/app/staticLibrary/api18/src/test'))
    .add(dirTmp('ohosTest')
      .add(copyTmp('/entry/stage/app/emptyAbility/api18/src/ohosTest/ets'))
      .add(copyTmp('/entry/stage/app/emptyAbility/api18/src/ohosTest/resources'))
      .add(renderTmp('/entry/stage/app/emptyAbility/api18/src/ohosTest/module.json5'))
    )
  )
  .add(renderTmp('/module/stage/app/staticLibrary/api18/build-profile.json5'))
  .add(copyTmp('/module/stage/app/staticLibrary/api18/Index.ets'))
  .add(copyTmp('/module/stage/app/common/hvigorfile-har.ts', 'hvigorfile.ts'))
  .add(copyTmp('/module/stage/app/common/obfuscation-rules.txt'))
  .add(copyTmp('/module/stage/app/common/consumer-rules.txt'))
  .add(renderTmp('/module/stage/app/common/oh-package.json5'));

moduleBuilder.add(staticLibraryOption, staticLibraryTemplate, initFun);

const staticLibraryWithCOption: ModuleTemplateOption = ModuleTemplateOptionBuilder.builder()
  .abilityType(AbilityType.Application)
  .apiType(APIType.STAGE)
  .apiVersion(CURRENT_HMOS_API)
  .language(LanguageType.ArkTs)
  .moduleTemplateType(ModuleTemplateType.StaticLibraryWithC)
  .runtimeOS(RuntimeOSType.HarmonyOS)
  .build();

const staticLibraryWithCTemplate: DirTemplateCreator = (dirName) => dirTmp(dirName)
  .add(dirTmp('libs')
    .add(dirTmp('arm64-v8a'))
  )
  .add(dirTmp('src')
    .add(dirTmp('main')
      .add(copyTmp('/module/stage/app/staticLibraryWithC/api18/src/main/cpp'))
      .add(copyTmp('/module/stage/app/staticLibraryWithC/api18/src/main/ets'))
      .add(copyTmp('/module/stage/app/staticLibraryWithC/api18/src/main/resources'))
      .add(renderTmp('/module/stage/app/common/api18/src/main/module-har.json5', 'module.json5'))
    )
    .add(copyTmp('/module/stage/app/common/api18/src/test'))
  )
  .add(renderTmp('/module/stage/app/common/api18/build-profile-har.json5', 'build-profile.json5'))
  .add(copyTmp('/module/stage/app/common/Index-MainPage.ets','Index.ets'))
  .add(copyTmp('/module/stage/app/common/hvigorfile-har.ts', 'hvigorfile.ts'))
  .add(copyTmp('/module/stage/app/common/obfuscation-rules.txt'))
  .add(copyTmp('/module/stage/app/common/consumer-rules.txt'))
  .add(renderTmp('/module/stage/app/staticLibraryWithC/api18/oh-package.json5'));

moduleBuilder.add(staticLibraryWithCOption, staticLibraryWithCTemplate, initFun);

const shareNativeCLibraryOption: ModuleTemplateOption = ModuleTemplateOptionBuilder.builder()
  .abilityType(AbilityType.Application)
  .apiType(APIType.STAGE)
  .apiVersion(CURRENT_HMOS_API)
  .language(LanguageType.ArkTs)
  .moduleTemplateType(ModuleTemplateType.SharedLibraryWithC)
  .runtimeOS(RuntimeOSType.HarmonyOS)
  .build();

const shareNativeCLibraryTemplate: DirTemplateCreator = (dirName) => dirTmp(dirName)
  .add(dirTmp('src')
    .add(dirTmp('main')
      .add(dirTmp('cpp')
        .add(dirTmp('types'))
        .add(dirTmp('libentry'))
        .add(copyTmp('/module/stage/app/shareNativeCLibrary/api18/src/main/cpp/types/libentry/index.d.ts'))
        .add(renderTmp('/module/stage/app/shareNativeCLibrary/api18/src/main/cpp/types/libentry/oh-package.json5'))
        .add(copyTmp('/module/stage/app/shareNativeCLibrary/api18/src/main/cpp/CMakeLists.txt'))
        .add(renderTmp('/module/stage/app/shareNativeCLibrary/api18/src/main/cpp/hello.cpp'))
      )
      .add(dirTmp('ets')
        .add(copyTmp('/module/stage/app/shareNativeCLibrary/api18/src/main/ets/components/mainpage'))
      )
      .add(dirTmp('resources')
        .add(dirTmp('base')
          .add(dirTmp('element')
            .add(copyTmp('/module/stage/app/shareNativeCLibrary/api18/src/main/resources/base/element/color.json'))
            .add(copyTmp('/module/stage/app/shareNativeCLibrary/api18/src/main/resources/base/element/string.json'))
          )
          .add(copyTmp('/module/stage/app/shareNativeCLibrary/api18/src/main/resources/base/media'))
          .add(copyTmp('/module/stage/app/shareNativeCLibrary/api18/src/main/resources/base/profile'))
        )
        .add(copyTmp('/module/stage/app/shareNativeCLibrary/api18/src/main/resources/en_US'))
        .add(dirTmp('rawfile'))
        .add(copyTmp('/module/stage/app/shareNativeCLibrary/api18/src/main/resources/zh_CN'))
      )
      .add(renderTmp('/module/stage/app/shareNativeCLibrary/api18/src/main/module.json5'))
    )
    .add(copyTmp('/module/stage/app/shareNativeCLibrary/api18/src/test'))
  )
  .add(renderTmp('/module/stage/app/shareNativeCLibrary/api18/build-profile.json5'))
  .add(copyTmp('/module/stage/app/common/hvigorfile-hsp.ts', 'hvigorfile.ts'))
  .add(copyTmp('/module/stage/app/common/obfuscation-rules.txt'))
  .add(renderTmp('/module/stage/app/common/oh-package.json5'));

moduleBuilder.add(shareNativeCLibraryOption, shareNativeCLibraryTemplate, nativeInitFun);
